
package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingElderDto;
import com.zzyl.enums.ElderStatusEnum;
import com.zzyl.service.ElderService;
import com.zzyl.vo.ElderCheckInInfoVo;
import com.zzyl.vo.ElderPageQueryVo;
import com.zzyl.vo.retreat.ElderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 客户老人关联 Controller
 */
@RestController
@RequestMapping("/elder")
@Api(tags = "老人")
public class ElderController {

    @Resource
    private ElderService elderService;

    /**
     * 列表
     */
    @GetMapping("/selectList")
    @ApiOperation(value = "列表")
    public ResponseResult selectList() {
        List<ElderVo> elderVos = elderService.selectList();
        return ResponseResult.success(elderVos);
    }

    @GetMapping("/pageQuery")
    @ApiOperation(value = "老人分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "老人姓名，模糊查询", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "idCardNo", value = "身份证号，精确查询", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "status", value = "状态，0：入住中，1：已退住", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageNum", value = "页码", example = "1", required = true, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页面大小", example = "10", required = true, dataTypeClass = Integer.class)
    })
    public ResponseResult<PageResponse<ElderPageQueryVo>> pageQuery(@RequestParam(value = "name", required = false) String name,
                                                                    @RequestParam(value = "idCardNo", required = false) String idCardNo,
                                                                    @RequestParam(value = "status", required = false) String status,
                                                                    @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return ResponseResult.success(elderService.pageQuery(name, idCardNo, status, pageNum, pageSize));
    }

    @GetMapping("/checkInInfo/{id}")
    @ApiOperation(value = "老人入住信息查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "老人id", required = true, dataTypeClass = Long.class)
    })
    public ResponseResult<ElderCheckInInfoVo> checkInInfo(@PathVariable("id") Long id) {
        return ResponseResult.success(elderService.checkInInfo(id));
    }

    /**
     * 设置护理员
     *
     * @param nursingElders
     */
    @PutMapping("/setNursing")
    @ApiOperation(value = "设置护理员", notes = "设置护理员")
    public ResponseResult setNursing(@RequestBody List<NursingElderDto> nursingElders) {
        elderService.setNursing(nursingElders);
        return ResponseResult.success();
    }


    @GetMapping("/selectByIdCard")
    @ApiOperation(value = "身份证号", notes = "身份证号")
    public ResponseResult selectByIdCard(@RequestParam String idCard) {
        return ResponseResult.success(elderService.selectByIdCardAndStatus(idCard, ElderStatusEnum.CHECK_IN.getOrdinal()));
    }
}


